package cn.quicklydoit.entity;


import cn.quicklydoit.config.Group;
import cn.quicklydoit.config.Sex;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.time.LocalDate;

@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "x_user")
@Schema(description = "用户实体")
public class User {

    @Id
    @Column
    @Schema(title = "unique",name = "id",required = true)
    private Long id;

    @Column
    @Schema(title="姓名",name="name",required = true)
    private String name;

    @Column
    @Schema(title="密码",name = "password",required = true)
    private String password;

    @Column
    @Schema(title = "消息",name = "message")
    private String message;

    @Column
    @Schema(title = "年龄",name="age",maximum = "120",minimum = "0",required = true)
    private Integer age;

    @Column
    @Schema(title = "性别",name="sex",required = true)
    private Sex sex=Sex.fromCode(0);

    @Column
    @Schema(title = "生日",name="birthDay",required = true)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDate birthDay;

    /**
     * 当前登录次数  后期存入redis 用于调整token
     */
    @Column
    @Schema(title = "登录次数",name="currentTimes",required = true)
    private Long currentTimes;

    /**
     * 当前登录ip 后期存入redis 用于调整token
     */
    @Column
    @Schema(title = "登录ip地址",name="currentIp",required = true)
    private String currentIp;


    @Column
    @Schema(title= "角色",name="roles",required = true)
    private Group roles= Group.USER;

    @Column
    @Schema(title = "邮箱",name = "email",required = true)
    private String email;

    /**
     * 不做数据库存储
     */
    @Transient
    private String token;

    /**
     * 验证码
     */
    @Transient
    private String validCode;
}
